package Java0108;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

//服务器
public class Java04 {
    public static void main(String[] args) {
        //(4)网络+ io 是一体

        //客户端 -> 服务器
        // navicat -> Mysql
    }
}
class Server{
    public static void main(String[] args) throws IOException {
        //创建一个服务器套接字
        ServerSocket serverSocket = new ServerSocket(8081);
        while(true) {
            //创建一个套接字,接受请求
            Socket socket = serverSocket.accept();
            //从套接字中获取输入流
            InputStream inputStream = socket.getInputStream();
            byte[] arr = new byte[1024];
            int len = inputStream.read(arr);
            System.out.println(new String(arr, 0, len));

        }
    }
}
//客户端
class Client{
    public static void main(String[] args) throws IOException {
        //创建套接字对象：需要指定ip和port
        //ipconfig
        Socket socket = new Socket("192.168.1.146",8081);
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("wwww".getBytes(StandardCharsets.UTF_8));

    }

}
